package com.mw.job.disruptor;

import com.lmax.disruptor.ExceptionHandler;
import com.mw.job.bean.DataBean;
import com.mw.job.context.SpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * Created by mengdexuan on 2017/9/18 18:05.
 */
public class DisruptorExceptionHandler implements ExceptionHandler<DataBean> {

	private static Logger log = LoggerFactory.getLogger(DisruptorExceptionHandler.class);

	JdbcTemplate jdbcTemplate = SpringContextUtil.getBean(JdbcTemplate.class);

	@Override
	public void handleEventException(Throwable ex, long sequence, DataBean event) {
		log.error("任务出错！",ex);
		log.info("sequence --> "+sequence);
		log.info("event --> "+event);

		jdbcTemplate.update("update test set status = 4 where id = "+ event.getId());

		ex.printStackTrace();
	}

	@Override
	public void handleOnStartException(Throwable ex) {
		log.error("onStartException",ex);
	}

	@Override
	public void handleOnShutdownException(Throwable ex) {
		log.error("onShutdownException",ex);
	}
}
